package com.yangguang.huahui.mvp.presenter;

import com.yangguang.huahui.R;
import com.yangguang.huahui.entity.HttpResult;
import com.yangguang.huahui.entity.Login;
import com.yangguang.huahui.mvp.model.LoginModel;
import com.yangguang.huahui.mvp.view.LoginView;
import com.yangguang.huahui.rx.RxManager;
import com.yangguang.huahui.rx.RxSubscriber;

import java.io.IOException;

import okhttp3.ResponseBody;

/**
 * Created by Administrator on 2017/3/1.
 */

public class LoginPresenter extends BasePresenter<LoginView>{
    LoginModel loginModel;

    public LoginPresenter() {
        loginModel = new LoginModel();
    }
    public void login(String phone, int type, String password, String code, double lat, double lng){
        mSubscription = RxManager.getInstance().doSubscribe(loginModel.login(phone, type, password, code, lat, lng), new RxSubscriber<Login>(false) {
            @Override
            protected void _onNext(Login login) {
                mView.onSuccess(login);
            }

            @Override
            protected void _onError() {
                mView.onError();
            }
        });
    }
    public void getCode(String phone){
        mSubscription = RxManager.getInstance().doSubscribe(loginModel.getCode(phone), new RxSubscriber<HttpResult>(false) {
            @Override
            protected void _onNext(HttpResult httpResult) {
                mView.onCode(httpResult);
            }

            @Override
            protected void _onError() {
                mView.onError();
            }
        });
    }

}
